class Solution {
public:
    vector<vector<int>> generate(int numRows) {
        vector<vector<int>> res;
        if (numRows == 0) return res;
        res.push_back({ 1 });

        for (int i = 1; i < numRows; ++i) {
            vector<int> preRow = res.back();
            vector<int> curRow;
            curRow.push_back(1);
            for (int j = 1; j < i; ++j)
                curRow.push_back(preRow[j - 1] + preRow[j]);
            curRow.push_back(1);
            res.push_back(curRow);
        }
        return res;
    }
};